home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / uip / other / emactovi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-11  |  1.9 KB  |  84 lines

  1. /*
  2.  * emactovi - convert from EMAC-style two file input to single file for vi
  3.  *
  4.  * When EMACS is presented with 2 files, it puts them both on the screen
  5.  * in seperate windows. Vi, in the same situation, starts up on only the
  6.  * first file. This filter copies the 2 files together, adding a reference
  7.  * line and inclusion marks (i.e. '>').
  8.  *
  9.  * usage:
  10.  *    emactovi editor file1 file2
  11.  *
  12.  * Emactovi processes file1 into file2 and then exec's editor on file2.
  13.  *
  14.  * Author
  15.  *    Edward C. Bennett <edward@engr.uky.edu>
  16.  */
  17. #include    <stdio.h>
  18. #ifdef SYS5
  19. #include    <string.h>
  20. #else    /* SYS5 */
  21. #include    <strings.h>
  22. #endif    /* SYS5 */
  23. #include    <ctype.h>
  24.  
  25. main(argc, argv)
  26. int argc;
  27. char **argv;
  28. {
  29.     register    FILE    *fpi, *fpo;
  30.     register    char    *p, buf[BUFSIZ];
  31.     FILE            *fopen();
  32.     char            *program;
  33.  
  34.     if (argc != 3)
  35.         exit(1);
  36.  
  37.     program = "emactovi";    /* Notice that argv[0] is our editor of choice,
  38.                     NOT the name of this program. */
  39.  
  40.     /*
  41.      * These should never fail, but let's be careful out there.
  42.      */
  43.     if ((fpi = fopen(argv[1], "r")) == NULL) {
  44.         fprintf(stderr, "%s: cannot open %s\n", program, argv[1]);
  45.         exit(1);
  46.     }
  47.     if ((fpo = fopen(argv[2], "w")) == NULL) {
  48.         fprintf(stderr, "%s: cannot open %s\n", program, argv[2]);
  49.         exit(1);
  50.     }
  51.  
  52.     while (fgets(buf, BUFSIZ, fpi) != (char *)NULL) {
  53.         if (strncmp(buf, "Date:", 5) == 0) {
  54.             if ((p = index(buf, '\n')) != (char *)NULL)
  55.                 *p = '\0';    /* remove new-line */
  56.  
  57.             p = &(buf[5]);
  58.             while (isspace(*p))
  59.                 p++;
  60.  
  61.             fprintf(fpo, "In your letter dated %s, you wrote:\n>\n", p);
  62.             break;
  63.         }
  64.         /* End of header, no Date: line found */
  65.         if (buf[0] == '\n') {
  66.             fprintf(fpo, "You recently wrote:\n>\n");
  67.             break;
  68.         }
  69.     }
  70.  
  71.     if (fseek(fpi, 0, 0) != 0) {    /* rewind input file */
  72.         fprintf(stderr, "%s: fseek() error on %s\n", program, argv[1]);
  73.         exit(1);
  74.     }
  75.     while (fgets(buf, BUFSIZ, fpi) != (char *)NULL)
  76.         fprintf(fpo, ">%s", buf);
  77.  
  78.     fclose(fpi);
  79.     fclose(fpo);
  80.  
  81.     execlp(argv[0], argv[0], argv[2], (char *)0);
  82.     exit(1);
  83. }
  84.